// pages/circle/square/cpns/hot-topic/index.js
Component({
  externalClasses: ["class"],
  /**
   * 组件的属性列表
   */
  properties: {
    topics: {
      type: Array,
      value: [
        { title: "城市美食推荐" },
        { title: "周末去哪玩" },
        { title: "本地好店分享" },
        { title: "城市夜景摄影" },
        { title: "城旅社区最受欢迎景点", isHot: true },
        { title: "城市徒步路线" },
        { title: "单身交友" },
        { title: "本地活动" },
        { title: "城市攻略" },
        { title: "生活小贴士" },
        { title: "城市吐槽", isHot: true },
        { title: "许愿池" },
      ]
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    datas: []
  },

  lifetimes: {
    attached: function() {
      this.handleTopics()
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleTopics: function() {
      const res = []
      let tempArr = []
      for(const index in this.properties.topics) {
        const item = this.properties.topics[index]
        tempArr.push(item)
        if (tempArr.length === 6 || index == this.properties.topics.length - 1) {
          res.push([tempArr.slice(0, 3), tempArr.slice(3)])
          tempArr = []
        }
      }
      this.setData({
        datas: res
      })
    },
    
    onTopicTap: function(e) {
      const topic = e.currentTarget.dataset.topic
      
      wx.showModal({
        title: '热门话题',
        content: '话题：' + topic.title + '\n\n是否进入话题讨论？',
        showCancel: true,
        cancelText: '取消',
        confirmText: '进入',
        success: function(res) {
          if (res.confirm) {
            wx.showToast({
              title: '话题页面开发中',
              icon: 'none'
            })
          }
        }
      })
    }
  }
})
